<!--
 * @Author: xiaodong 565071984@qq.com
 * @Date: 2022-05-09 21:35:06
 * @LastEditors: xiaodong 565071984@qq.com
 * @LastEditTime: 2022-05-14 19:48:31
 * @FilePath: /ywl/Volumes/ExtremeSSD/项目/小票/src/views/systemManagement/roleManagement/components/UserManagementEdit.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    width="500px"
    @close="close"
  >
 
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="选择玩法"   prop="sc_name">
        <el-select v-model="form.sc_name" placeholder="请选玩法" @change="changeScene">
          <el-option
            v-for="(item, index) in sceneList"
            :key="index"
            :label="item.name"
            :value="item.name"
          >{{item.name}}</el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="选择场次"  prop="scn_name">
       <el-select v-model="form.scn_name" placeholder="请选场次" @change="changeScn">
          <el-option
            v-for="(item, index) in scnList"
            :key="index"
            :label="item.name"
            :value="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        :label="$t('order.lottryDate') /*开奖日期*/"
        prop="kj_time"
      >
         <el-date-picker
                  v-model="form.kj_time"
                   type="date"
                  value-format="timestamp"
               
                  :range-separator="$t('order.to') /*至*/"
                  :start-placeholder="$t('order.beginDate') /*开始日期*/"
                  :end-placeholder="$t('order.endDate') /*结束日期*/"
                  align="right"
                ></el-date-picker>
      </el-form-item>

      <el-form-item
        :label="$t('order.winningNumber') /*中奖号码*/"
        prop="code"
      >
        <el-input v-model="form.code" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item :label="$t('accountManage.isUnk1') /*是否有灰球*/">
        <el-radio-group v-model="form.is_gray">
          <el-radio :label="0">{{$t('accountManage.none') /*无*/}}</el-radio>
          <el-radio :label="1">{{$t('accountManage.has') /*有*/}}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        :label="$t('order.ballWinningNumber') /*灰球中奖号码*/"
        prop="gray_code"
      >
        <el-input v-model="form.gray_code" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">
        {{ $t('common.cancel') /*取 消*/ }}
      </el-button>
      <el-button type="primary" @click="save">
        {{ $t('common.sure') /*确 定*/ }}
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { doEdit } from '@/api/roleManagement'
 import { getScenes,getSceneNumList,addKj } from '@/api/business.js'
  export default {
    name: 'RoleManagementEdit',
    data() {
      return {
        form: {
          id: '',
        },
        rules: {
          permission: [
            { required: true, trigger: 'blur', message: '请输入权限码' },
          ],
        },
        title: '',
        sceneList:[],
        scnList:[],
        dialogFormVisible: false,
      }
    },
    created() {},
    methods: {
      changeScene(e){
        this.form.sc_id=this.sceneList.filter(res=>{
          return res.name==e;
        })[0].sc_id;
        this.getScnList();
      },
      changeScn(e){
        this.form.scn_id=this.scnList.filter(res=>{
          return res.name==e;
        })[0].scn_id;
      },
      showEdit(row) {
        if (!row) {
          this.title = '新增玩法'
        } else {
          this.title = '编辑'
          this.form = Object.assign({}, row)
        }
        this.dialogFormVisible = true
        this.getScenes();
      },
      getScenes(){
           let rq={
             limit:99,
             page:1
           }
          getScenes(rq).then(res=>{
            if(res.code==0){
              this.sceneList=res.data.data;
            }
          }) 
      },
       getScnList(){
         if(!this.form.sc_id){
           return;
         }
           let rq={
             sc_id:this.form.sc_id

           }
            getSceneNumList(rq).then(res=>{
              if(res.code==0){
                this.scnList=res.data;
              }
            }) 
      },
      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            this.form.kj_time=this.form.kj_time/1000;
            const { msg } = await addKj(this.form)
            this.$baseMessage(msg, 'success')
            this.$emit('fetch-data')
            this.close()
          } else {
            return false
          }
        })
      },
    },
  }
</script>
